package com.yungu.swift.order.processor;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.order.model.vo.PayVo;
import com.yungu.swift.system.finance.model.dto.FinancePrepayDto;
import com.yungu.swift.system.finance.service.FinancePrepayService;
import com.yungu.swift.utils.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 预支付处理器
 *
 * @author Zerrion
 * @date 2017/5/8
 */
@Component
public class PrePayProcessor implements PayProcessor {
    private static final Logger logger = LoggerFactory.getLogger(PrePayProcessor.class);
    @Reference
    FinancePrepayService financePrepayService;

    @Override
    public void process(PayVo payVo) {
        FinancePrepayDto financePrepayDto = financePrepayService.list(MapUtils.build("serialNumber",
                payVo.getTradeNo())).getData().get(0);
        if (financePrepayDto != null) {
            //更新实体
            FinancePrepayDto updateFinancePrepayDto = new FinancePrepayDto();
            updateFinancePrepayDto.setUuid(financePrepayDto.getUuid());
            updateFinancePrepayDto.setStatus(1);
            financePrepayService.edit(updateFinancePrepayDto);
            logger.info(payVo.getDescription() + "--处理预支付逻辑完毕");
        } else {
            logger.warn(payVo.getDescription() + "--查找不到预支付信息");
        }

    }
}
